<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class auth extends MX_Controller
{
    public function __construct()
    {
        parent::__construct();
        //$this->load->model('auth_model');
    }

    public function index()
    {
        $this->load->view('users/login');
    }

    public function login()
    {
        $params = array();
        if ($_POST) {
            $params['username'] = trim($this->input->post("USR"));
            $params['pass'] = imd5($this->input->post("PWD"));
            
            $userInfo = $this->auth_model->checkUserLogin($params);  
            if (empty($userInfo)) {
                notify_set_messages(t('Username or Password not valid'), 'login');
                return redirect(site_url('auth'));
            }elseif ($userInfo['status'] == 0) {
                notify_set_messages(t('Username not yet active!'), 'login');
                return redirect(site_url('auth'));
            } else {
                $this->auth_model->addSession($userInfo);
                redirect(base_url());
            }
        } else {
            $this->load->view('users/login');
        }
      
    }

    public function logout()
    {
        unset($_SESSION["CI_LOGIN"]);
        $this->session->sess_destroy();
        //$this->session->unset_userdata(array('auth'));
        redirect(site_url("auth/login"));
    }
}
